package logic

import (
	"context"
	"errors"
	"house/model/mysql"

	"house/house"
	"house/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShowListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShowListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowListLogic {
	return &ShowListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShowListLogic) ShowList(in *house.ShowListRequest) (*house.ShowListResponse, error) {
	// todo: add your logic here and delete this line

	var d mysql.Shop
	var err error

	if err = d.Find(); err != nil {
		logx.Error("查询失败")
		return nil, errors.New("查询失败")
	}
	if d.ID == 0 {
		logx.Error("未查询到此商品")
		return nil, errors.New("未查询到此商品")
	}
	return &house.ShowListResponse{
		Title:  d.Title,
		Info:   d.Info,
		Price:  float32(d.Price),
		Num:    d.Num,
		Image:  d.Image,
		UserId: int64(d.UserId),
		Audit:  int64(d.Audit),
	}, nil
}
